import urllib.request as ur
import urllib.parse as up
import json


kw = input('请输入英文：')
data = {
    'kw': kw,
}

# 对data进行url编码
data_url = up.urlencode(data)
# print(data_url)

request = ur.Request(
    url='https://fanyi.baidu.com/sug',
    # 字节编码
    data=data_url.encode('utf-8'),
)

# 生成json对象
response = ur.urlopen(request).read()
print(response)

# 转换为python对象
ret = json.loads(response)
# print(ret)

# 取值
translate = ret['data'][0]['v']
print(translate)
